import request from "@/utils/request";

export default {
  getInventoryList(searchModel) {
    return request({
      url: "/inventory/list",
      method: "get",
      params: {
        serialNumber: searchModel.serialNumber,
        productId: searchModel.productId,
        warehouseId: searchModel.warehouseId,
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
      },
    });
  },

  addInventory(inventory) {
    return request({
      url: "/inventory",
      method: "post",
      data: inventory,
    });
  },

  getInventoryById(id) {
    return request({
      url: `/inventory/${id}`,
      method: "get",
    });
  },

  saveInventory(inventory) {
    if (inventory.id == null && inventory.id == undefined) {
      return this.addInventory(inventory);
    }
    return this.updateInventory(inventory);
  },

  updateInventory(inventory) {
    return request({
      url: `/inventory`,
      method: "put",
      data: inventory,
    });
  },

  deleteInventoryById(id, qz_token) {
    return request({
      url: `/inventory/${id}`,
      method: "delete",
      data: qz_token,
    });
  },

  // 获取对应仓库的序列号
  getWarehouseInventory(inventory) {
    return request({
      url: `/inventory/getWarehouseInventory`,
      method: "get",
      params: inventory,
    });
  },

  // 获取对应仓库的序列号
  addInventorys(inventoryList, remark) {
    return request({
      url: `/inventory/addInventoryList`,
      method: "post",
      data: inventoryList,
      params: { remark: remark },
    });
  },

  // 获取在库序列号
  getInWarehouseSerialNumber(transferData) {
    return request({
      url: `/inventory/getInWarehouseSerialNumber`,
      method: "post",
      data: transferData,
    });
  },
};
